/* $Header: pi_colramps.c,v 2.3 03/06/24 12:25:53 przybyls Exp $ */

/***********************************************************************/
/*                                                                     */
/*                  Copyright Hewlett-Packard Co. 1991                 */
/*                                                                     */
/***********************************************************************/

/***********************************************************************/
/* MODULE NAME: pi_colramps.c                                          */
/* ============                                                        */
/*                                                                     */
/* Author:  Susan Merkel                                               */
/*                                                                     */
/* MODULE PURPOSE:  This module contains the Get, Set, and Validate    */
/*                  routines for the column pressure and flow ramps.   */
/*                                                                     */
/*                                                                     */
/*                                                                     */
/*                                                                     */
/***********************************************************************/


/*****************************/
/*   GLOBAL INCLUDE FILES    */
/*****************************/

#include <typedefs.h>
#include <p_wkfile.h>
#include <wkfile.h>
#include <p_status.h>
#include <ramps.h>
#include <zone_config.h>
#include <zone_status.h>
#include <status.h>
#include <math.h>
#include <error.h>
#include <list_mgmt.h>
#include <zone_ui.h>     /* to get time <--> millisec conversions */
#include <exception.h>
#include <glp.h>
#include <keyboard.h>
#include <run_ui.h>
#include <p_ui.h>

/*****************************/
/*   LOCAL INCLUDE FILES     */
/*****************************/

#include "proto.h"

/*****************************/
/*   GLOBAL VARIABLES        */
/*****************************/


/*****************************/
/*   EXTERNAL VARIABLES      */
/*****************************/


/*****************************/
/*   LOCAL DEFINES           */
/*****************************/


/*****************************/
/*   STATIC VARIABLES        */
/*****************************/


/*****************************/
/*   IMPLEMENT SECTION       */
/*****************************/

/**begin_proto**/
#pragma SECTION PROG=rom3
/**end_proto**/

/***********************************************************************/
/* FUNCTION:                                                           */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:                                                            */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/***********************************************************************/
/**begin_proto**/

INT32 GetColRampMaxFinalFlow ( )

/**end_proto**/
{
    return MAX_COL_FINAL_FLOW * DISPLAY_F_SCALE;
}


/**begin_proto**/

U_INT32 GetColRampMaxFinalFlowIu ( pCOLUMN_STATUS status )

/**end_proto**/
{

    return ConvertFlowDisplayToIu( GetColRampMaxFinalFlow(), status->IU_Scaling );

}

/**begin_proto**/

UI_ERR ValidateColRampFinalFlow ( INT32 final_flow, pCOLUMN_STATUS status )

/**end_proto**/
{
     (void) status;

     if ( final_flow < 0 )                        return PARAM_TOO_SMALL;
     if ( final_flow > GetColRampMaxFinalFlow() ) return PARAM_TOO_LARGE;

     return OK;
}




/***********************************************************************/
/* FUNCTION:                                                           */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:                                                            */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/***********************************************************************/

/**begin_proto**/

void RangeCheckColumnFlowRamp( pCOLUMN_STATUS status )

/**end_proto**/
{
     U_INT32 max_flow;
     INT32   max_flow_rate;
     U_INT32 ramp_scale;
     U_INT32 col_scale;

     ramp_scale = status->Ramp_Setpt.Ramp_Flow_Scaling;
     col_scale  = status->IU_Scaling;

     max_flow = GetColRampMaxFinalFlowIu( status );

     if ( max_flow < QuadWordMultiplyDivide( GetRampInitValue( status->Ramp_Info ), col_scale, ramp_scale ) )
     {
         SetRampInitValue( status->Ramp_Info, QuadWordMultiplyDivide( max_flow, ramp_scale, col_scale ));
     }

     if ( max_flow < QuadWordMultiplyDivide( GetRampFinalValue( status->Ramp_Info, 1 ), col_scale, ramp_scale ) )
     {
         SetRampFinalValue( status->Ramp_Info, 1, QuadWordMultiplyDivide( max_flow, ramp_scale, col_scale ));
     }

     if ( max_flow < QuadWordMultiplyDivide( GetRampFinalValue( status->Ramp_Info, 2 ), col_scale, ramp_scale ) )
     {
         SetRampFinalValue( status->Ramp_Info, 2, QuadWordMultiplyDivide( max_flow, ramp_scale, col_scale ));
     }

     if ( max_flow < QuadWordMultiplyDivide( GetRampFinalValue( status->Ramp_Info, 3 ), col_scale, ramp_scale ) )
     {
         SetRampFinalValue( status->Ramp_Info, 3, QuadWordMultiplyDivide( max_flow, ramp_scale, col_scale ));
     }

     if ( max_flow < QuadWordMultiplyDivide( GetRampPostValue( status->Ramp_Info ), col_scale, ramp_scale ) )
     {
         SetRampPostValue( status->Ramp_Info, QuadWordMultiplyDivide( max_flow, ramp_scale, col_scale ));
     }

     max_flow_rate = ConvertFlowRateDisplayToIu ( GetRampMaxFlowRate(), col_scale );

     if ( max_flow_rate < (INT32)QuadWordMultiplyDivide( GetRampRate( status->Ramp_Info, 1 ), col_scale, ramp_scale ) )
     {
          SetRampRate( status->Ramp_Info, 1, QuadWordMultiplyDivide( max_flow_rate, ramp_scale, col_scale ) );
     }

     if ( max_flow_rate < (INT32)QuadWordMultiplyDivide( GetRampRate( status->Ramp_Info, 2 ), col_scale, ramp_scale ) )
     {
          SetRampRate( status->Ramp_Info, 2, QuadWordMultiplyDivide( max_flow_rate, ramp_scale, col_scale ) );
     }

     if ( max_flow_rate < (INT32)QuadWordMultiplyDivide( GetRampRate( status->Ramp_Info, 3 ), col_scale, ramp_scale ) )
     {
          SetRampRate( status->Ramp_Info, 3, QuadWordMultiplyDivide( max_flow_rate, ramp_scale, col_scale ) );
     }

}


/**begin_proto**/

void RangeCheckColumnPresRamp( pCOLUMN_STATUS status )

/**end_proto**/
{
     U_INT32 max_pres;
     INT32   max_pres_rate;
     U_INT32 ramp_scale;
     U_INT32 col_scale;

     ramp_scale = status->Ramp_Setpt.Ramp_Pres_Scaling;
     col_scale  = status->Dcm2_Per_IU;

     max_pres = GetSourceMaxPresIu( status );

     if ( max_pres < QuadWordMultiplyDivide( GetRampInitValue( status->Ramp_Info ), ramp_scale, col_scale ) )
     {
         SetRampInitValue( status->Ramp_Info, QuadWordMultiplyDivide( max_pres, col_scale, ramp_scale ));
     }

     if ( max_pres < QuadWordMultiplyDivide( GetRampFinalValue( status->Ramp_Info, 1 ), ramp_scale, col_scale ) )
     {
         SetRampFinalValue( status->Ramp_Info, 1, QuadWordMultiplyDivide( max_pres, col_scale, ramp_scale ));
     }

     if ( max_pres < QuadWordMultiplyDivide( GetRampFinalValue( status->Ramp_Info, 2 ), ramp_scale, col_scale ) )
     {
         SetRampFinalValue( status->Ramp_Info, 2, QuadWordMultiplyDivide( max_pres, col_scale, ramp_scale ));
     }

     if ( max_pres < QuadWordMultiplyDivide( GetRampFinalValue( status->Ramp_Info, 3 ), ramp_scale, col_scale ) )
     {
         SetRampFinalValue( status->Ramp_Info, 3, QuadWordMultiplyDivide( max_pres, col_scale, ramp_scale ));
     }

     if ( max_pres < QuadWordMultiplyDivide( GetRampPostValue( status->Ramp_Info ), ramp_scale, col_scale ) )
     {
         SetRampPostValue( status->Ramp_Info, QuadWordMultiplyDivide( max_pres, col_scale, ramp_scale ));
     }

     max_pres_rate = ConvertPresRateDisplayToIu ( GetRampMaxPresRate(), col_scale );

     if ( max_pres_rate < (INT32)QuadWordMultiplyDivide( GetRampRate( status->Ramp_Info, 1 ), ramp_scale, col_scale ) )
     {
          SetRampRate( status->Ramp_Info, 1, QuadWordMultiplyDivide( max_pres_rate, col_scale, ramp_scale ) );
     }

     if ( max_pres_rate < (INT32)QuadWordMultiplyDivide( GetRampRate( status->Ramp_Info, 2 ), ramp_scale, col_scale ) )
     {
          SetRampRate( status->Ramp_Info, 2, QuadWordMultiplyDivide( max_pres_rate, col_scale, ramp_scale ) );
     }

     if ( max_pres_rate < (INT32)QuadWordMultiplyDivide( GetRampRate( status->Ramp_Info, 3 ), ramp_scale, col_scale ) )
     {
          SetRampRate( status->Ramp_Info, 3, QuadWordMultiplyDivide( max_pres_rate, col_scale, ramp_scale ) );
     }

}


/**begin_proto**/

void RangeCheckColumnRamps( pCOLUMN_STATUS status )

/**end_proto**/
{
    if ( status->Wkfile->Control_Mode == RAMP_PRES )
    {
         RangeCheckColumnPresRamp( status );
    }
    else if ( status->Wkfile->Control_Mode == RAMP_FLOW )
    {
         RangeCheckColumnFlowRamp( status );
    }

}


/**begin_proto**/

INT32 GetColInitPres (pCOLUMN_STATUS status)

/**end_proto**/
{
  return  ConvertPresIuToDisplay (
             GetRampInitValue( (pRAMPINFO)(status->Ramp_Info) ),
             status->Ramp_Setpt.Ramp_Pres_Scaling);
}


/**begin_proto**/

INT32 DcGetColInitPres (pCOLUMN_STATUS status)

/**end_proto**/
{

   U_INT16 max_pres;
   U_INT16 pres;
   U_INT16 oven_temp;


       if ( !status->Config->Defined &&
            ( status->Wkfile->Control_Mode == CONST_FLOW ) &&
            SourcePressureControlled( status ))
       {
           /* setpt is a 25C setpt */

          pres = GetRampInitValue( (pRAMPINFO)(status->Ramp_Info) );
          oven_temp = GetOvenInitTemp();

          if (status->Config->Vacuum_Comp == ON)
          {
              pres = CalcPiFromPrevWVC( status, oven_temp, pres );
          }
          else
          {
              pres = CalcPiFromPrevWOVC( status, oven_temp, pres );
          }

          max_pres = GetSourceMaxPresIu( status );

          if ( pres > max_pres ) pres = max_pres;

          return ConvertPresIuToDcu ( pres, status->Ramp_Setpt.Ramp_Pres_Scaling);
       }
       else
       {
          return ConvertPresIuToDcu ( GetRampInitValue( (pRAMPINFO)(status->Ramp_Info) ),
                                      status->Ramp_Setpt.Ramp_Pres_Scaling);
       }
}



/**begin_proto**/


/**begin_proto**/

UI_ERR SetColInitPres (pCOLUMN_STATUS status, INT32 pres)

/**end_proto**/
{
    UI_ERR  error;
    U_INT32 init_pres;

    if ( (error = ValidateColumnHeadPres ( pres, status )) == OK )
    {
         init_pres = ConvertPresDisplayToIu( pres, status->Ramp_Setpt.Ramp_Pres_Scaling );
         ChangeColInitPres( status, init_pres, pres, GetCurrentOvenTemp() );
    }

    return error;
}

/**begin_proto**/

UI_ERR DcSetColInitPres (pCOLUMN_STATUS status, INT32 pres)

/**end_proto**/
{
    U_INT32 init_pres;
    INT32   pres_du;
    UI_ERR  error;

    init_pres = ConvertPresDcuToIu    (pres,        status->Ramp_Setpt.Ramp_Pres_Scaling );


    pres_du   = ConvertPresIuToDisplay( init_pres,  status->Ramp_Setpt.Ramp_Pres_Scaling );

    if ( (error = ValidateColumnHeadPres ( pres_du, status )) == OK )
    {

         ChangeColInitPres( status, init_pres, pres_du, GetOvenInitTemp() );
    }

    return error;
}

/**begin_proto**/

void ChangeColInitPres (pCOLUMN_STATUS status, U_INT32 init_pres, INT32 pres, U_INT16 oven_temp )

/**end_proto**/
{
  U_INT16 max_pres;
  U_INT16 ref_pres;
  BIT8    setpt_changed;


  if ( !status->Config->Defined &&
     ( status->Wkfile->Control_Mode == CONST_FLOW ) &&
       SourcePressureControlled( status ))
  {
       /* one can only reach this code via datacomm cmds.  The keyboard prohibits    */
       /* access to ramps unless one the column is in ramped mode.                   */

       /* undefined column const flow mode, pressure is relative to oven init temp   */
       /*  iq internally stores this value relative to 25C, make the conversion here */

       ref_pres  = CalcPiRefFromPi ( status, oven_temp, init_pres );

       if ( ref_pres  > ( max_pres = GetSourceMaxPresIu( status ) )) ref_pres = max_pres;

       setpt_changed = ( GetRampInitValue( (pRAMPINFO)(status->Ramp_Info) ) != ref_pres );
       SetRampInitValue( (pRAMPINFO)(status->Ramp_Info), ref_pres );

       if ( !RunActiveOrPostTime() )
       {
           status->Ramp_Setpt.Head_Pressure = QuadWordMultiplyDivide( ref_pres,
                                                         status->Ramp_Setpt.Ramp_Pres_Scaling,
                                                         status->Dcm2_Per_IU );
       }

  }
  else
  {
       setpt_changed = ( GetRampInitValue( (pRAMPINFO)(status->Ramp_Info) ) != init_pres );
       SetRampInitValue( (pRAMPINFO)(status->Ramp_Info), init_pres );

       if ( RampInitialValueActive( (pRAMPINFO)(status->Ramp_Info) ) )  /*!RunActiveOrPostTime() )*/
       {
           UpdateColumnHeadPres ( QuadWordMultiplyDivide( init_pres,
                                                         status->Ramp_Setpt.Ramp_Pres_Scaling,
                                                         status->Dcm2_Per_IU ),
                                      status,
                                      oven_temp );
       }
  }

  UpdateColumnSourceSetpts( status, GetOvenInitTemp() );

  if ( setpt_changed )
  {
       LogSetptChange( status->Position == 1 ? COL1_INIT_PRES : COL2_INIT_PRES, pres, (INT32)GetPresUnits() );
  }

}


/*****************************/
/*                           */
/*****************************/


/**begin_proto**/

INT32 GetColPresInitTime (pCOLUMN_STATUS status)

/**end_proto**/
{
  return  MilliSecsToTime ( GetRampInitTime( (pRAMPINFO)(status->Ramp_Info) ) );
}


/**begin_proto**/

INT32 DcGetColPresInitTime (pCOLUMN_STATUS status)

/**end_proto**/
{
  return  MilliSecsToTime( GetRampInitTime( (pRAMPINFO)(status->Ramp_Info) ) );
}


UI_ERR ChkColPneuInitTime (pCOLUMN_STATUS status, INT32 time)

{
  pINLET_STATUS i_status;

  if ( ( GetColumnControlMode(status )==CONST_PRES ) || ( GetColumnControlMode(status )==CONST_FLOW ) ) return OK ;

  i_status = ( (status->Config->Source == FRNT_INLET) ? pFRONT_INLET : pBACK_INLET ); /* assume inlet=back if not front */

  if (
       (GetColumnSource(status ) == i_status->Position         ) &&                   /* to verify the assumption */
       ( 0 != i_status->Wkfile->VI_Inj_Time                    ) &&
       (TimeToMilliSecs(time) <= (TIME_SETPT)i_status->Wkfile->VI_Inj_Time )
     )  return COL_TIME1_CONFLICT;

  return CheckTimeSetpt ( time );

}



/**begin_proto**/

UI_ERR SetColPresInitTime (pCOLUMN_STATUS status, INT32 time)

/**end_proto**/
{
  UI_ERR  error;

  if ( (error = ChkColPneuInitTime( status,time )) != OK ) return error;

  ChangeColPresInitTime ( status,  time );

  return error;
}


/**begin_proto**/

UI_ERR DcSetColPresInitTime (pCOLUMN_STATUS status, INT32 time )

/**end_proto**/
{
  UI_ERR  error;

  if ( (error = ChkColPneuInitTime( status,time )) != OK )
  {
     VISamplingEndChk(status ); /* incase mode<=ramp w/ SmplgEnd >= OLD col_init_time */
     return error;
  };

  ChangeColPresInitTime ( status,  time);

  return error;
}



/**begin_proto**/

void ChangeColPresInitTime (pCOLUMN_STATUS status, INT32 time)

/**end_proto**/
{
  BIT8 setpt_changed;

  setpt_changed = ( GetRampInitTime( (pRAMPINFO)(status->Ramp_Info) ) != TimeToMilliSecs(time) );
  SetRampInitTime( (pRAMPINFO)(status->Ramp_Info), TimeToMilliSecs(time) );

  if (setpt_changed)
  {
       LogSetptChange( status->Position == 1 ? COL1_INIT_TIME : COL2_INIT_TIME, time, 0 );
  }
}

/*****************************/
/*                           */
/*****************************/



/**begin_proto**/

INT32 GetColPresRate (pCOLUMN_STATUS status, U_INT8 rampnum)

/**end_proto**/
{


  return  ConvertPresRateIuToDisplay(
            GetRampRate( (pRAMPINFO)(status->Ramp_Info), rampnum ),
            status->Ramp_Setpt.Ramp_Pres_Scaling);
}


/**begin_proto**/

INT32 DcGetColPresRate (pCOLUMN_STATUS status, U_INT8 rampnum)

/**end_proto**/
{

  return  ConvertPresRateIuToDcu(
            GetRampRate( (pRAMPINFO)(status->Ramp_Info), rampnum ),
            status->Ramp_Setpt.Ramp_Pres_Scaling);
}



/**begin_proto**/

UI_ERR SetColPresRate (pCOLUMN_STATUS status, INT32 setpt, U_INT8 rampnum)

/**end_proto**/
{
  U_INT32 rate_setpt;
  UI_ERR  error;

  if ( ( rampnum == 1 ) && ( setpt != 0 ) && ( status->Wkfile->Control_Mode != RAMP_PRES )) return NOT_ALLOWED;

  if ( (error = ValidatePresRate( setpt )) != OK ) return error;

  rate_setpt = ConvertPresRateDisplayToIu (setpt, status->Ramp_Setpt.Ramp_Pres_Scaling );

  ChangeColPresRate( status, rate_setpt, setpt, rampnum );

  return OK;
}




/**begin_proto**/

UI_ERR DcSetColPresRate (pCOLUMN_STATUS status, INT32 setpt, U_INT8 rampnum)

/**end_proto**/
{
  U_INT32 rate_setpt;
  INT32   rate_du;

  if ( ( rampnum == 1 ) && ( setpt != 0 ) && ( status->Wkfile->Control_Mode != RAMP_PRES )) return NOT_ALLOWED;

  rate_setpt = ConvertPresRateDcuToIu (setpt,  status->Ramp_Setpt.Ramp_Pres_Scaling);
  rate_du    = ConvertPresIuToDisplay( rate_setpt, status->Ramp_Setpt.Ramp_Pres_Scaling);

  ChangeColPresRate( status, rate_setpt, rate_du, rampnum );

  return OK;
}



/**begin_proto**/

void ChangeColPresRate (pCOLUMN_STATUS status, U_INT32 rate, INT32 setpt, U_INT8 rampnum)

/**end_proto**/
{
  BIT8 setpt_changed;


  setpt_changed = ( GetRampRate( (pRAMPINFO)(status->Ramp_Info), rampnum ) != rate );
  SetRampRate( (pRAMPINFO)(status->Ramp_Info), rampnum, rate );

  if (setpt_changed)
  {
       switch ( rampnum )
       {
           case 1:  LogSetptChange( status->Position == 1 ? COL1_PRES_RATE1 : COL2_PRES_RATE1, setpt, (INT32)GetPresUnits() );
                    break;
           case 2:  LogSetptChange( status->Position == 1 ? COL1_PRES_RATE2 : COL2_PRES_RATE2, setpt, (INT32)GetPresUnits() );
                    break;
           case 3:  LogSetptChange( status->Position == 1 ? COL1_PRES_RATE3 : COL2_PRES_RATE3, setpt, (INT32)GetPresUnits() );
                    break;
       }
  }
}


/*****************************/
/*                           */
/*****************************/



/**begin_proto**/

INT32 GetColPresFinalVal (pCOLUMN_STATUS status, U_INT8 rampnum)

/**end_proto**/
{

  return ConvertPresIuToDisplay(
              GetRampFinalValue( (pRAMPINFO)(status->Ramp_Info), rampnum ),
              status->Ramp_Setpt.Ramp_Pres_Scaling);
}



/**begin_proto**/

INT32 DcGetColPresFinalVal (pCOLUMN_STATUS status, U_INT8 rampnum)

/**end_proto**/
{
  return ConvertPresIuToDcu(
              GetRampFinalValue( (pRAMPINFO)(status->Ramp_Info), rampnum ),
              status->Ramp_Setpt.Ramp_Pres_Scaling);
}




/**begin_proto**/

UI_ERR SetColPresFinalVal (pCOLUMN_STATUS status, INT32 pres, U_INT8 rampnum)

/**end_proto**/
{
  U_INT32 pres_final_val;
  UI_ERR  error;

  if ( (error = ValidateColumnHeadPres ( pres, status )) != OK ) return error;
  {
      pres_final_val = ConvertPresDisplayToIu (pres, status->Ramp_Setpt.Ramp_Pres_Scaling );

      ChangeColPresFinalVal ( status,  pres_final_val,  pres,  rampnum);
  }

  return error;
}



/**begin_proto**/

UI_ERR DcSetColPresFinalVal (pCOLUMN_STATUS status, INT32 pres, U_INT8 rampnum)

/**end_proto**/
{
  U_INT32 pres_final_val;
  INT32   pres_du;
  UI_ERR  error;

  pres_final_val = ConvertPresDcuToIu (pres, status->Ramp_Setpt.Ramp_Pres_Scaling);
  pres_du        = ConvertPresIuToDisplay ( pres_final_val, status->Ramp_Setpt.Ramp_Pres_Scaling );

  if ( (error = ValidateColumnHeadPres ( pres_du, status )) == OK )

  {

      ChangeColPresFinalVal ( status,  pres_final_val,  pres_du,  rampnum);

  }

  return error;
}


/**begin_proto**/

void ChangeColPresFinalVal (pCOLUMN_STATUS status, U_INT32 pres_final_val, INT32 pres, U_INT8 rampnum)

/**end_proto**/
{
  BIT8 setpt_changed;


  setpt_changed = ( GetRampFinalValue( (pRAMPINFO)(status->Ramp_Info), rampnum ) != pres_final_val );
  SetRampFinalValue( (pRAMPINFO)(status->Ramp_Info), rampnum, pres_final_val );

  if (setpt_changed)
  {
       switch ( rampnum )
       {
           case 1:  LogSetptChange( status->Position == 1 ? COL1_FINAL_PRES1 : COL2_FINAL_PRES1, pres, (INT32)GetPresUnits() );
                    break;
           case 2:  LogSetptChange( status->Position == 1 ? COL1_FINAL_PRES2 : COL2_FINAL_PRES2, pres, (INT32)GetPresUnits() );
                    break;
           case 3:  LogSetptChange( status->Position == 1 ? COL1_FINAL_PRES3 : COL2_FINAL_PRES3, pres, (INT32)GetPresUnits() );
                    break;
       }
  }
}


/*****************************/
/*                           */
/*****************************/

/**begin_proto**/

INT32 GetColPresFinalTime (pCOLUMN_STATUS status, U_INT8 rampnum)

/**end_proto**/
{

  return MilliSecsToTime(
           GetRampFinalTime( (pRAMPINFO)(status->Ramp_Info), rampnum) );
}




/**begin_proto**/

INT32 DcGetColPresFinalTime (pCOLUMN_STATUS status, U_INT8 rampnum)

/**end_proto**/
{

  return MilliSecsToTime( GetRampFinalTime( (pRAMPINFO)(status->Ramp_Info), rampnum) );
}




/**begin_proto**/

UI_ERR SetColPresFinalTime (pCOLUMN_STATUS status, INT32 time, U_INT8 rampnum )

/**end_proto**/
{
  UI_ERR  error;

  if ( (error = CheckTimeSetpt ( time )) != OK ) return error;

  ChangeColPresFinalTime ( status,  time, rampnum );

  return error;
}


/**begin_proto**/

UI_ERR DcSetColPresFinalTime (pCOLUMN_STATUS status, INT32 time, U_INT8 rampnum )

/**end_proto**/
{
  UI_ERR  error;

  if ( (error = CheckTimeSetpt ( time )) != OK ) return error;

  ChangeColPresFinalTime ( status,  time, rampnum );

  return error;
}



/**begin_proto**/

void ChangeColPresFinalTime (pCOLUMN_STATUS status, INT32 time, U_INT8 rampnum )

/**end_proto**/
{
  BIT8 setpt_changed;

  setpt_changed = ( GetRampFinalTime( (pRAMPINFO)(status->Ramp_Info), rampnum ) != TimeToMilliSecs(time) );
  SetRampFinalTime( (pRAMPINFO)(status->Ramp_Info), rampnum, TimeToMilliSecs(time) );

  if (setpt_changed)
  {
       switch ( rampnum )
       {
           case 1:  LogSetptChange( status->Position == 1 ? COL1_FINAL_TIME1 : COL2_FINAL_TIME1, 1, time );
                    break;
           case 2:  LogSetptChange( status->Position == 1 ? COL1_FINAL_TIME2 : COL2_FINAL_TIME2, 2, time );
                    break;
           case 3:  LogSetptChange( status->Position == 1 ? COL1_FINAL_TIME3 : COL2_FINAL_TIME3, 3, time );
                    break;
       }
  }

}


/*****************************/
/*                           */
/*****************************/

/**begin_proto**/

INT32 GetColInitFlow (pCOLUMN_STATUS status)

/**end_proto**/
{
  return  ConvertFlowIuToDisplay (
             GetRampInitValue( (pRAMPINFO)(status->Ramp_Info) ),
             status->Ramp_Setpt.Ramp_Flow_Scaling);
}


/**begin_proto**/

INT32 DcGetColInitFlow (pCOLUMN_STATUS status)

/**end_proto**/
{
  return  ConvertFlowIuToDcu (
             GetRampInitValue( (pRAMPINFO)(status->Ramp_Info) ),
             status->Ramp_Setpt.Ramp_Flow_Scaling);
}



/**begin_proto**/


/**begin_proto**/

UI_ERR SetColInitFlow (pCOLUMN_STATUS status, INT32 flow)

/**end_proto**/
{
    UI_ERR  error;
    U_INT32 init_flow;

    if ( (error = ValidateColumnVFlow ( flow, status )) == OK )
    {
         init_flow = ConvertFlowDisplayToIu( flow, status->Ramp_Setpt.Ramp_Flow_Scaling );
         ChangeColInitFlow( status, init_flow, flow, GetCurrentOvenTemp() );
    }

    return error;
}

/**begin_proto**/

UI_ERR DcSetColInitFlow (pCOLUMN_STATUS status, INT32 flow)

/**end_proto**/
{
    U_INT32 init_flow;
    INT32   flow_du;
    UI_ERR  error;

    init_flow = ConvertFlowDcuToIu    (flow,        status->Ramp_Setpt.Ramp_Flow_Scaling );
    flow_du   = ConvertFlowIuToDisplay( init_flow,  status->Ramp_Setpt.Ramp_Flow_Scaling );

    if ( (error = DcValidateColumnVFlow ( flow_du, status )) == OK )
    {

         ChangeColInitFlow( status, init_flow, flow_du, GetOvenInitTemp() );
    }

    return error;
}

/**begin_proto**/

void ChangeColInitFlow (pCOLUMN_STATUS status, U_INT32 init_flow, INT32 flow, U_INT16 oven_temp )

/**end_proto**/
{
  BIT8 setpt_changed;


  setpt_changed = ( GetRampInitValue( (pRAMPINFO)(status->Ramp_Info) ) != init_flow );
  SetRampInitValue( (pRAMPINFO)(status->Ramp_Info), init_flow );

  if ( RampInitialValueActive( (pRAMPINFO)(status->Ramp_Info) ) )  /*!RunActiveOrPostTime() )*/
  {
       UpdateColumnVFlow ( QuadWordMultiplyDivide( init_flow,
                                                   status->IU_Scaling,
                                                   status->Ramp_Setpt.Ramp_Flow_Scaling ),
                                  status,
                                  oven_temp );
  }

  UpdateColumnSourceSetpts( status, oven_temp );

  if (setpt_changed)
  {
       LogSetptChange( status->Position == 1 ? COL1_INIT_FLOW : COL2_INIT_FLOW, flow, 0 );
  }

}


/*****************************/
/*                           */
/*****************************/

/**begin_proto**/

INT32 GetColFlowInitTime (pCOLUMN_STATUS status)

/**end_proto**/
{
  return  MilliSecsToTime ( GetRampInitTime( (pRAMPINFO)(status->Ramp_Info) ) );
}


/**begin_proto**/

INT32 DcGetColFlowInitTime (pCOLUMN_STATUS status)

/**end_proto**/
{
  return  MilliSecsToTime( GetRampInitTime( (pRAMPINFO)(status->Ramp_Info) ) );
}




/**begin_proto**/

UI_ERR SetColFlowInitTime (pCOLUMN_STATUS status, INT32 time)

/**end_proto**/
{
  UI_ERR  error;

  if ( (error = ChkColPneuInitTime( status,time )) != OK ) return error;

  ChangeColFlowInitTime ( status, time);

  return error;
}


/**begin_proto**/

UI_ERR DcSetColFlowInitTime (pCOLUMN_STATUS status,INT32 time )

/**end_proto**/
{
  UI_ERR  error;

  if ( (error = ChkColPneuInitTime( status,time )) != OK )
  {
     VISamplingEndChk(status ); /* incase mode<=ramp w/ SmplgEnd >= OLD col_init_time */
     return error;
  };

  ChangeColFlowInitTime ( status, time);

  return error;
}



/**begin_proto**/

void ChangeColFlowInitTime (pCOLUMN_STATUS status, INT32 time)

/**end_proto**/
{
  BIT8 setpt_changed;

  setpt_changed = ( GetRampInitTime( (pRAMPINFO)(status->Ramp_Info) ) != TimeToMilliSecs(time) );
  SetRampInitTime( (pRAMPINFO)(status->Ramp_Info), TimeToMilliSecs(time) );

  if (setpt_changed)
  {
       LogSetptChange( status->Position == 1 ? COL1_INIT_TIME : COL2_INIT_TIME, time, 0 );
  }
}


/*****************************/
/*                           */
/*****************************/



/**begin_proto**/

INT32 GetColFlowRate (pCOLUMN_STATUS status, U_INT8 rampnum)

/**end_proto**/
{

  return  ConvertFlowRateIuToDisplay(
            GetRampRate( (pRAMPINFO)(status->Ramp_Info), rampnum ),
            status->Ramp_Setpt.Ramp_Flow_Scaling);
}


/**begin_proto**/

INT32 DcGetColFlowRate (pCOLUMN_STATUS status, U_INT8 rampnum)

/**end_proto**/
{

  return  ConvertFlowRateIuToDcu(
            GetRampRate( (pRAMPINFO)(status->Ramp_Info), rampnum ),
            status->Ramp_Setpt.Ramp_Flow_Scaling);
}



/**begin_proto**/

UI_ERR SetColFlowRate (pCOLUMN_STATUS status, INT32 setpt, U_INT8 rampnum)

/**end_proto**/
{
  U_INT32 rate_setpt;
  UI_ERR  error;

  if ( ( rampnum == 1 ) && ( setpt != 0 ) && ( status->Wkfile->Control_Mode != RAMP_FLOW )) return NOT_ALLOWED;

  if ( (error = ValidateFlowRate( setpt )) != OK ) return error;

  rate_setpt = ConvertFlowRateDisplayToIu (setpt, status->Ramp_Setpt.Ramp_Flow_Scaling );

  ChangeColFlowRate( status, rate_setpt, setpt, rampnum );

  return OK;
}




/**begin_proto**/

UI_ERR DcSetColFlowRate (pCOLUMN_STATUS status, INT32 setpt, U_INT8 rampnum)

/**end_proto**/
{
  U_INT32 rate_setpt;
  INT32   rate_du;
  UI_ERR  error;

  if ( ( rampnum == 1 ) && ( setpt != 0 ) && ( status->Wkfile->Control_Mode != RAMP_FLOW )) return NOT_ALLOWED;


  rate_setpt = ConvertFlowRateDcuToIu (setpt,  status->Ramp_Setpt.Ramp_Flow_Scaling);
  rate_du    = ConvertFlowIuToDisplay( rate_setpt, status->Ramp_Setpt.Ramp_Flow_Scaling);

  if ( (error = ValidateFlowRate( rate_du )) != OK ) return error;

  ChangeColFlowRate( status, rate_setpt, rate_du, rampnum );

  return OK;
}



/**begin_proto**/

void ChangeColFlowRate (pCOLUMN_STATUS status, U_INT32 rate, INT32 setpt, U_INT8 rampnum)

/**end_proto**/
{
  BIT8 setpt_changed;


  setpt_changed = ( GetRampRate( (pRAMPINFO)(status->Ramp_Info), rampnum ) != rate );
  SetRampRate( (pRAMPINFO)(status->Ramp_Info), rampnum, rate );

  if (setpt_changed)
  {
       switch ( rampnum )
       {
           case 1:  LogSetptChange( status->Position == 1 ? COL1_FLOW_RATE1 : COL2_FLOW_RATE1, 1, setpt );
                    break;
           case 2:  LogSetptChange( status->Position == 1 ? COL1_FLOW_RATE2 : COL2_FLOW_RATE2, 2, setpt );
                    break;
           case 3:  LogSetptChange( status->Position == 1 ? COL1_FLOW_RATE3 : COL2_FLOW_RATE3, 3, setpt );
                    break;
       }
  }
}


/*****************************/
/*                           */
/*****************************/



/**begin_proto**/

INT32 GetColFlowFinalVal (pCOLUMN_STATUS status, U_INT8 rampnum)

/**end_proto**/
{

  return ConvertFlowIuToDisplay(
              GetRampFinalValue( (pRAMPINFO)(status->Ramp_Info), rampnum ),
              status->Ramp_Setpt.Ramp_Flow_Scaling);
}



/**begin_proto**/

INT32 DcGetColFlowFinalVal (pCOLUMN_STATUS status, U_INT8 rampnum)

/**end_proto**/
{
  return ConvertFlowIuToDcu(
              GetRampFinalValue( (pRAMPINFO)(status->Ramp_Info), rampnum ),
              status->Ramp_Setpt.Ramp_Flow_Scaling);
}




/**begin_proto**/

UI_ERR SetColFlowFinalVal (pCOLUMN_STATUS status, INT32 flow, U_INT8 rampnum)

/**end_proto**/
{
  U_INT32 flow_final_val;
  UI_ERR  error;

  if ( (error = ValidateColRampFinalFlow ( flow, status )) == OK )
  {
      flow_final_val = ConvertFlowDisplayToIu (flow, status->Ramp_Setpt.Ramp_Flow_Scaling );

      ChangeColFlowFinalVal ( status,  flow_final_val,  flow,  rampnum);
  }

  return error;
}



/**begin_proto**/

UI_ERR DcSetColFlowFinalVal (pCOLUMN_STATUS status, INT32 flow, U_INT8 rampnum)

/**end_proto**/
{
  U_INT32 flow_final_val;
  INT32   flow_du;
  UI_ERR  error;

  flow_final_val = ConvertFlowDcuToIu (flow, status->Ramp_Setpt.Ramp_Flow_Scaling);
  flow_du        = ConvertFlowIuToDisplay ( flow_final_val, status->Ramp_Setpt.Ramp_Flow_Scaling );

  if ( (error = ValidateColRampFinalFlow ( flow_du, status )) == OK )
  {

      ChangeColFlowFinalVal ( status,  flow_final_val,  flow_du,  rampnum);

  }

  return error;
}


/**begin_proto**/

void ChangeColFlowFinalVal (pCOLUMN_STATUS status, U_INT32 flow_final_val, INT32 flow, U_INT8 rampnum)

/**end_proto**/
{
  BIT8 setpt_changed;


  setpt_changed = ( GetRampFinalValue( (pRAMPINFO)(status->Ramp_Info), rampnum ) != flow_final_val );
  SetRampFinalValue( (pRAMPINFO)(status->Ramp_Info), rampnum, flow_final_val );

  if (setpt_changed)
  {
       switch ( rampnum )
       {
           case 1:  LogSetptChange( status->Position == 1 ? COL1_FINAL_FLOW1 : COL2_FINAL_FLOW1, 1, flow );
                    break;
           case 2:  LogSetptChange( status->Position == 1 ? COL1_FINAL_FLOW2 : COL2_FINAL_FLOW2, 2, flow );
                    break;
           case 3:  LogSetptChange( status->Position == 1 ? COL1_FINAL_FLOW3 : COL2_FINAL_FLOW3, 3, flow );
                    break;
       }
  }
}


/*****************************/
/*                           */
/*****************************/

/**begin_proto**/

INT32 GetColFlowFinalTime (pCOLUMN_STATUS status, U_INT8 rampnum)

/**end_proto**/
{

  return MilliSecsToTime(
           GetRampFinalTime( (pRAMPINFO)(status->Ramp_Info), rampnum) );
}




/**begin_proto**/

INT32 DcGetColFlowFinalTime (pCOLUMN_STATUS status, U_INT8 rampnum)

/**end_proto**/
{

  return MilliSecsToTime( GetRampFinalTime( (pRAMPINFO)(status->Ramp_Info), rampnum) );
}




/**begin_proto**/

UI_ERR SetColFlowFinalTime (pCOLUMN_STATUS status, INT32 time, U_INT8 rampnum )

/**end_proto**/
{
  UI_ERR  error;

  if ( (error = CheckTimeSetpt ( time )) != OK ) return error;

  ChangeColFlowFinalTime ( status,  time, rampnum );

  return error;
}


/**begin_proto**/

UI_ERR DcSetColFlowFinalTime (pCOLUMN_STATUS status, INT32 time, U_INT8 rampnum )

/**end_proto**/
{
  UI_ERR  error;

  if ( (error = CheckTimeSetpt ( time )) != OK ) return error;

  ChangeColFlowFinalTime ( status,  time, rampnum );

  return error;
}



/**begin_proto**/

void ChangeColFlowFinalTime (pCOLUMN_STATUS status, INT32 time, U_INT8 rampnum )

/**end_proto**/
{
  BIT8 setpt_changed;

  setpt_changed = ( GetRampFinalTime( (pRAMPINFO)(status->Ramp_Info), rampnum ) != TimeToMilliSecs(time) );
  SetRampFinalTime( (pRAMPINFO)(status->Ramp_Info), rampnum, TimeToMilliSecs(time));

  if (setpt_changed)
  {
       switch ( rampnum )
       {
           case 1:  LogSetptChange( status->Position == 1 ? COL1_FINAL_TIME1 : COL2_FINAL_TIME1, 1, time );
                    break;
           case 2:  LogSetptChange( status->Position == 1 ? COL1_FINAL_TIME2 : COL2_FINAL_TIME2, 2, time );
                    break;
           case 3:  LogSetptChange( status->Position == 1 ? COL1_FINAL_TIME3 : COL2_FINAL_TIME3, 3, time );
                    break;
       }
  }

}


/*****************************/
/*                           */
/*****************************/


/**begin_proto**/

INT32 GetAuxInitPres (pAUX_STATUS status)

/**end_proto**/
{
  return  ConvertPresIuToDisplay (
             GetRampInitValue( (pRAMPINFO)(status->Ramp_Info) ),
             status->Ramp_Setpt.Ramp_Pres_Scaling);
}


/**begin_proto**/

INT32 DcGetAuxInitPres (pAUX_STATUS status)

/**end_proto**/
{
  return  ConvertPresIuToDcu (
             GetRampInitValue( (pRAMPINFO)(status->Ramp_Info) ),
             status->Ramp_Setpt.Ramp_Pres_Scaling);
}



/**begin_proto**/


/**begin_proto**/

UI_ERR SetAuxInitPres (pAUX_STATUS status, INT32 pres)

/**end_proto**/
{
    UI_ERR  error;
    U_INT32 init_pres;

    if ( (error = ValidateAuxPresSetpt ( pres, status )) == OK )
    {
         init_pres = ConvertPresDisplayToIu( pres, status->Ramp_Setpt.Ramp_Pres_Scaling );
         ChangeAuxInitPres( status, init_pres, pres );
    }

    return error;
}

/**begin_proto**/

UI_ERR DcSetAuxInitPres (pAUX_STATUS status, INT32 pres)

/**end_proto**/
{
    U_INT32 init_pres;
    INT32   pres_du;
    UI_ERR  error;

    init_pres = ConvertPresDcuToIu    (pres,        status->Ramp_Setpt.Ramp_Pres_Scaling );
    pres_du   = ConvertPresIuToDisplay( init_pres,  status->Ramp_Setpt.Ramp_Pres_Scaling );

    if ( (error = ValidateAuxPresSetpt ( pres_du, status )) == OK )
    {

         ChangeAuxInitPres( status, init_pres, pres_du );
    }

    return error;
}

/**begin_proto**/

void ChangeAuxInitPres (pAUX_STATUS status, U_INT32 init_pres, INT32 pres)

/**end_proto**/
{
  BIT8 setpt_changed;


  setpt_changed = ( GetRampInitValue( (pRAMPINFO)(status->Ramp_Info) ) != init_pres );
  SetRampInitValue( (pRAMPINFO)(status->Ramp_Info), init_pres );

  if (( RampInitialValueActive((pRAMPINFO)status->Ramp_Info) ) && ( !status->Controlled_By_Column ))
  {
       UpdateAuxPresStatus( QuadWordMultiplyDivide( init_pres,
                                                      status->Ramp_Setpt.Ramp_Pres_Scaling,
                                                      status->Dcm2_Per_IU ),
                                  status, status->Dcm2_Per_IU );
  }

  if (setpt_changed)
  {
       LogSetptChange( status->Position == AUX_3 ? AUX3_INIT_PRES :
                       status->Position == AUX_4 ? AUX4_INIT_PRES :
                                                   AUX5_INIT_PRES, pres, (INT32)GetPresUnits() );
  }

}


/*****************************/
/*                           */
/*****************************/

/**begin_proto**/

INT32 GetAuxPresInitTime (pAUX_STATUS status)

/**end_proto**/
{
  return  MilliSecsToTime ( GetRampInitTime( (pRAMPINFO)(status->Ramp_Info) ) );
}


/**begin_proto**/

INT32 DcGetAuxPresInitTime (pAUX_STATUS status)

/**end_proto**/
{
  return  MilliSecsToTime( GetRampInitTime( (pRAMPINFO)(status->Ramp_Info) ) );
}




/**begin_proto**/

UI_ERR SetAuxPresInitTime (pAUX_STATUS status, INT32 time)

/**end_proto**/
{
  UI_ERR  error;

  if ( (error = CheckTimeSetpt ( time )) != OK ) return error;

  ChangeAuxPresInitTime ( status, time);

  return error;
}


/**begin_proto**/

UI_ERR DcSetAuxPresInitTime (pAUX_STATUS status, INT32 time )

/**end_proto**/
{
  UI_ERR  error;

  if ( (error = CheckTimeSetpt ( time )) != OK ) return error;

  ChangeAuxPresInitTime ( status,  time);

  return error;
}



/**begin_proto**/

void ChangeAuxPresInitTime (pAUX_STATUS status, INT32 time)

/**end_proto**/
{
  BIT8 setpt_changed;

  setpt_changed = ( GetRampInitTime( (pRAMPINFO)(status->Ramp_Info) ) != TimeToMilliSecs(time) );
  SetRampInitTime( (pRAMPINFO)(status->Ramp_Info), TimeToMilliSecs(time) );

  if (setpt_changed)
  {
       LogSetptChange( status->Position == AUX_3 ? AUX3_INIT_TIME :
                       status->Position == AUX_4 ? AUX4_INIT_TIME :
                                                   AUX5_INIT_TIME,  time, 0 );
  }
}


/*****************************/
/*                           */
/*****************************/



/**begin_proto**/

INT32 GetAuxPresRate (pAUX_STATUS status, U_INT8 rampnum)

/**end_proto**/
{

  return  ConvertPresRateIuToDisplay(
            GetRampRate( (pRAMPINFO)(status->Ramp_Info), rampnum ),
            status->Ramp_Setpt.Ramp_Pres_Scaling);
}


/**begin_proto**/

INT32 DcGetAuxPresRate (pAUX_STATUS status, U_INT8 rampnum)

/**end_proto**/
{

  return  ConvertPresRateIuToDcu(
            GetRampRate( (pRAMPINFO)(status->Ramp_Info), rampnum ),
            status->Ramp_Setpt.Ramp_Pres_Scaling);
}



/**begin_proto**/

UI_ERR SetAuxPresRate (pAUX_STATUS status, INT32 setpt, U_INT8 rampnum)

/**end_proto**/
{
  U_INT32 rate_setpt;
  UI_ERR  error;

  if ( (error = ValidatePresRate( setpt )) != OK ) return error;

  rate_setpt = ConvertPresRateDisplayToIu (setpt, status->Ramp_Setpt.Ramp_Pres_Scaling );

  ChangeAuxPresRate( status, rate_setpt, setpt, rampnum );

  return OK;
}




/**begin_proto**/

UI_ERR DcSetAuxPresRate (pAUX_STATUS status, INT32 setpt, U_INT8 rampnum)

/**end_proto**/
{
  U_INT32 rate_setpt;
  INT32   rate_du;

  rate_setpt = ConvertPresRateDcuToIu (setpt,  status->Ramp_Setpt.Ramp_Pres_Scaling);
  rate_du    = ConvertPresIuToDisplay( rate_setpt, status->Ramp_Setpt.Ramp_Pres_Scaling);

  ChangeAuxPresRate( status, rate_setpt, rate_du, rampnum );

  return OK;
}



/**begin_proto**/

void ChangeAuxPresRate (pAUX_STATUS status, U_INT32 rate, INT32 setpt, U_INT8 rampnum)

/**end_proto**/
{
  BIT8 setpt_changed;


  setpt_changed = ( GetRampRate( (pRAMPINFO)(status->Ramp_Info), rampnum ) != rate );
  SetRampRate( (pRAMPINFO)(status->Ramp_Info), rampnum, rate );

  if (setpt_changed)
  {
       switch ( rampnum )
       {
           case 1:  LogSetptChange( status->Position == AUX_3 ? AUX3_PRES_RATE1 :
                                    status->Position == AUX_4 ? AUX4_PRES_RATE1 :
                                                                AUX5_PRES_RATE1,  setpt, (INT32)GetPresUnits() );
                    break;
           case 2:  LogSetptChange( status->Position == AUX_3 ? AUX3_PRES_RATE2 :
                                    status->Position == AUX_4 ? AUX4_PRES_RATE2 :
                                                                AUX5_PRES_RATE2,  setpt, (INT32)GetPresUnits() );
                    break;
           case 3:  LogSetptChange( status->Position == AUX_3 ? AUX3_PRES_RATE3 :
                                    status->Position == AUX_4 ? AUX4_PRES_RATE3 :
                                                                AUX5_PRES_RATE3,  setpt, (INT32)GetPresUnits() );
                    break;
       }
  }
}


/*****************************/
/*                           */
/*****************************/



/**begin_proto**/

INT32 GetAuxPresFinalVal (pAUX_STATUS status, U_INT8 rampnum)

/**end_proto**/
{

  return ConvertPresIuToDisplay(
              GetRampFinalValue( (pRAMPINFO)(status->Ramp_Info), rampnum ),
              status->Ramp_Setpt.Ramp_Pres_Scaling);
}



/**begin_proto**/

INT32 DcGetAuxPresFinalVal (pAUX_STATUS status, U_INT8 rampnum)

/**end_proto**/
{
  return ConvertPresIuToDcu(
              GetRampFinalValue( (pRAMPINFO)(status->Ramp_Info), rampnum ),
              status->Ramp_Setpt.Ramp_Pres_Scaling);
}




/**begin_proto**/

UI_ERR SetAuxPresFinalVal (pAUX_STATUS status, INT32 pres, U_INT8 rampnum)

/**end_proto**/
{
  U_INT32 pres_final_val;
  UI_ERR  error;

  if ( (error = ValidateAuxPresSetpt ( pres, status )) != OK ) return error;
  {
      pres_final_val = ConvertPresDisplayToIu (pres, status->Ramp_Setpt.Ramp_Pres_Scaling );

      ChangeAuxPresFinalVal ( status,  pres_final_val,  pres,  rampnum);
  }

  return error;
}



/**begin_proto**/

UI_ERR DcSetAuxPresFinalVal (pAUX_STATUS status, INT32 pres, U_INT8 rampnum)

/**end_proto**/
{
  U_INT32 pres_final_val;
  INT32   pres_du;
  UI_ERR  error;

  pres_final_val = ConvertPresDcuToIu (pres, status->Ramp_Setpt.Ramp_Pres_Scaling);
  pres_du        = ConvertPresIuToDisplay ( pres_final_val, status->Ramp_Setpt.Ramp_Pres_Scaling );

  if ( (error = ValidateAuxPresSetpt ( pres_du, status )) == OK )
  {

      ChangeAuxPresFinalVal ( status,  pres_final_val,  pres_du,  rampnum);

  }

  return error;
}


/**begin_proto**/

void ChangeAuxPresFinalVal (pAUX_STATUS status, U_INT32 pres_final_val, INT32 pres, U_INT8 rampnum)

/**end_proto**/
{
  BIT8 setpt_changed;


  setpt_changed = ( GetRampFinalValue( (pRAMPINFO)(status->Ramp_Info), rampnum ) != pres_final_val );
  SetRampFinalValue( (pRAMPINFO)(status->Ramp_Info), rampnum, pres_final_val );

  if (setpt_changed)
  {
       switch ( rampnum )
       {
           case 1:  LogSetptChange( status->Position == AUX_3 ? AUX3_FINAL_PRES1 :
                                    status->Position == AUX_4 ? AUX4_FINAL_PRES1 :
                                                                AUX5_FINAL_PRES1,  pres, (INT32)GetPresUnits() );
                    break;
           case 2:  LogSetptChange( status->Position == AUX_3 ? AUX3_FINAL_PRES2 :
                                    status->Position == AUX_4 ? AUX4_FINAL_PRES2 :
                                                                AUX5_FINAL_PRES2,  pres, (INT32)GetPresUnits() );
                    break;
           case 3:  LogSetptChange( status->Position == AUX_3 ? AUX3_FINAL_PRES3 :
                                    status->Position == AUX_4 ? AUX4_FINAL_PRES3 :
                                                                AUX5_FINAL_PRES3,  pres, (INT32)GetPresUnits() );
                    break;
       }
  }
}


/*****************************/
/*                           */
/*****************************/

/**begin_proto**/

INT32 GetAuxPresFinalTime (pAUX_STATUS status, U_INT8 rampnum)

/**end_proto**/
{

  return MilliSecsToTime(
           GetRampFinalTime( (pRAMPINFO)(status->Ramp_Info), rampnum) );
}




/**begin_proto**/

INT32 DcGetAuxPresFinalTime (pAUX_STATUS status, U_INT8 rampnum)

/**end_proto**/
{

  return MilliSecsToTime( GetRampFinalTime( (pRAMPINFO)(status->Ramp_Info), rampnum) );
}




/**begin_proto**/

UI_ERR SetAuxPresFinalTime (pAUX_STATUS status, INT32 time, U_INT8 rampnum )

/**end_proto**/
{
  UI_ERR  error;

  if ( (error = CheckTimeSetpt ( time )) != OK ) return error;

  ChangeAuxPresFinalTime ( status,  time, rampnum );

  return error;
}


/**begin_proto**/

UI_ERR DcSetAuxPresFinalTime (pAUX_STATUS status, INT32 time, U_INT8 rampnum )

/**end_proto**/
{
  UI_ERR  error;

  if ( (error = CheckTimeSetpt ( time )) != OK ) return error;

  ChangeAuxPresFinalTime ( status,  time, rampnum );

  return error;
}



/**begin_proto**/

void ChangeAuxPresFinalTime (pAUX_STATUS status, INT32 time, U_INT8 rampnum )

/**end_proto**/
{
  BIT8 setpt_changed;

  setpt_changed = ( GetRampFinalTime( (pRAMPINFO)(status->Ramp_Info), rampnum ) != TimeToMilliSecs(time) );
  SetRampFinalTime( (pRAMPINFO)(status->Ramp_Info), rampnum, TimeToMilliSecs(time) );

  if (setpt_changed)
  {
       switch ( rampnum )
       {
           case 1:  LogSetptChange( status->Position == AUX_3 ? AUX3_FINAL_TIME1 :
                                    status->Position == AUX_4 ? AUX4_FINAL_TIME1 :
                                                                AUX5_FINAL_TIME1, 1, time );
                    break;
           case 2:  LogSetptChange( status->Position == AUX_3 ? AUX3_FINAL_TIME2 :
                                    status->Position == AUX_4 ? AUX4_FINAL_TIME2 :
                                                                AUX5_FINAL_TIME2,  2, time );
                    break;
           case 3:  LogSetptChange( status->Position == AUX_3 ? AUX3_FINAL_TIME3 :
                                    status->Position == AUX_4 ? AUX4_FINAL_TIME3 :
                                                                AUX5_FINAL_TIME3,  3, time );
                    break;
       }
  }

}


/*****************************/
/*                           */
/*****************************/


/***********************************************************************/
/* FUNCTION:                                                           */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:                                                            */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/***********************************************************************/
/**begin_proto**/

U_INT16 CalcTempFromTime( INT32 time )

/**end_proto**/
{

    INT32   cum_time;
    U_INT8  rate_index;
    INT32   ramp_time;

    RAMPTBL  *oven;
    RAMPS   *ramps;

    oven  = Oven_Temp_Info.ramp_table;
    ramps = Oven_Temp_Info.ramps;


    if ( time <= oven->init_time ) return ( oven->init_value );

    /* if no ramps, then just stretch the init temp */
    if ( ramps[0].rate == 0 ) return ( oven->init_value );

    ramp_time = (INT32)(( ramps[0].final_value - oven->init_value ) / ramps[0].rate);

    cum_time = oven->init_time;

    if ( time <= cum_time + ramp_time  )
    {
          /* time exists during rate */
          return ( oven->init_value + ramps[0].rate * ( time - oven->init_time ) );
    }

    cum_time = oven->init_time + ramp_time;

    if ( time <= cum_time + ramps[0].final_time )
    {
        return ( ramps[0].final_value );
    }

    cum_time = cum_time + ramps[0].final_time;

    for ( rate_index = 1 ; rate_index < OVEN_RAMP_LEVELS ; rate_index++ )
    {

        /* NOTE : THIS IS THE RETURN IF TIME > RUN_LENGTH ! */

        /* if no more ramps, then just stretch the previous temp */
        if ( ramps[rate_index].rate == 0 ) return ( ramps[rate_index-1].final_value );

        ramp_time =
               (ramps[rate_index].final_value - ramps[rate_index-1].final_value) / ramps[rate_index].rate ;

        if ( time <= cum_time + ramp_time )
        {
              /* time exists during rate */
              return ( ramps[rate_index-1].final_value + ramps[rate_index].rate * ( time - cum_time ) );
        }

        cum_time +=  ramp_time;

        if ( time <= cum_time + (INT32)ramps[rate_index].final_time )  return ( ramps[rate_index].final_value );

        cum_time = cum_time + ramps[rate_index].final_time;
    }


    return 0; /* keep lint happy */

}


#define RAMP_F_UNITS(x) ( QuadWordMultiplyDivide( (x), status->Ramp_Setpt.Ramp_Flow_Scaling, status->IU_Scaling  ) )
#define RAMP_P_UNITS(x) ( QuadWordMultiplyDivide( (x), status->Dcm2_Per_IU, status->Ramp_Setpt.Ramp_Pres_Scaling ) )

#define COL_F_UNITS(x)  ( QuadWordMultiplyDivide( (x), status->IU_Scaling, status->Ramp_Setpt.Ramp_Flow_Scaling ) )
#define COL_P_UNITS(x)  ( QuadWordMultiplyDivide( (x), status->Ramp_Setpt.Ramp_Pres_Scaling, status->Dcm2_Per_IU ) )


/***********************************************************************/
/* FUNCTION:                                                           */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:                                                            */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/***********************************************************************/
/**begin_proto**/

void ConvertPresRampToFlowRamp( pCOLUMN_STATUS status )

/**end_proto**/
{

    INT32 cum_time;
    INT32 rate_time;
    U_INT8 rate_index;
    U_INT32 delta;
    U_INT32 init_flow;
    U_INT32 final_flow;
    U_INT32 flow_rate;
    U_INT16 Po;

    RAMPTBL *setpts;
    RAMPS   *ramps;


    setpts = ((pRAMPINFO)GetRampInfoPtr( status ))->ramp_table;
    ramps  = ((pRAMPINFO)GetRampInfoPtr( status ))->ramps;

    Po = GetNtpOutletPressure ( status );

    if ( ramps[0].rate == 0 )
    {
         rate_time = 0;
    }
    else
    {
         delta = ( ramps[0].final_value > setpts->init_value)?
                   ramps[0].final_value - setpts->init_value :
                   setpts->init_value - ramps[0].final_value ;

        /* msec  =                           psi  *  msec/min  / psi/min      */
         rate_time = QuadWordMultiplyDivide( delta, 60 * 1000  , ramps[0].rate  );
    }

    cum_time = setpts->init_time;

    init_flow = CalcVFlow ( status,
                            pOvenRamp()->ramp_table->init_value,
                            COL_P_UNITS( setpts->init_value ),
                            Po );

    final_flow = CalcVFlow ( status,
                            CalcTempFromTime( cum_time + rate_time ),
                            COL_P_UNITS( ramps[0].final_value ),
                            Po );

    if ( rate_time == 0 )
    {
         flow_rate = 0;
    }
    else
    {
         /* mL/min/min */
         flow_rate = QuadWordMultiplyDivide ( (final_flow > init_flow) ?
                                               final_flow - init_flow  :
                                               init_flow  - final_flow ,  /* mL/min */
                                              60 * 1000,                  /* msec/min */
                                              rate_time );                /* msec     */
    }

    setpts->init_value = RAMP_F_UNITS(init_flow);

    init_flow = final_flow;
    cum_time = cum_time + rate_time + ramps[0].final_time;


    for ( rate_index = 1; rate_index < RAMP_LEVELS ; rate_index++ )
    {

        if ( ramps[rate_index].rate == 0 )
        {
             rate_time = 0;
        }
        else
        {
            delta = ( ramps[rate_index  ].final_value > ramps[rate_index-1].final_value)?
                      ramps[rate_index  ].final_value - ramps[rate_index-1].final_value :
                      ramps[rate_index-1].final_value - ramps[rate_index].final_value   ;

            /* msec  =                           psi  *  msec/min  / psi/min      */
            rate_time = QuadWordMultiplyDivide( delta, 60 * 1000 , ramps[rate_index].rate );
        }

        ramps[rate_index-1].rate        = RAMP_F_UNITS(flow_rate);
        ramps[rate_index-1].final_value = RAMP_F_UNITS(final_flow);

        cum_time = cum_time + rate_time;

        final_flow = CalcVFlow ( status,
                                CalcTempFromTime( cum_time + rate_time ),
                                COL_P_UNITS(ramps[rate_index].final_value),
                                Po );

        if ( rate_time == 0 )
        {
             flow_rate = 0;
        }
        else
        {
             /* mL/min/min */
            flow_rate = QuadWordMultiplyDivide ( (final_flow > init_flow) ?
                                                  final_flow - init_flow  :
                                                  init_flow  - final_flow ,  /* mL/min */
                                                  60 * 1000,               /* msec/min */
                                                  rate_time );             /* msec     */
        }


        init_flow = final_flow;
        cum_time = cum_time + ramps[rate_index].final_time;

    }

    ramps[rate_index-1].rate        = RAMP_F_UNITS(flow_rate);
    ramps[rate_index-1].final_value = RAMP_F_UNITS(final_flow);


    /* now handle post time */

    setpts->post_value = RAMP_F_UNITS(CalcVFlow ( status,
                                                  pOvenRamp()->ramp_table->post_value,
                                                  COL_P_UNITS(setpts->post_value),
                                                  Po ));

    SetRampType( (pRAMPINFO)GetRampInfoPtr( status ), FLOW_RAMP );

}


/***********************************************************************/
/* FUNCTION:                                                           */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:                                                            */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/***********************************************************************/
/**begin_proto**/

void ConvertFlowRampToPresRamp( pCOLUMN_STATUS status )

/**end_proto**/
{

    INT32 cum_time;
    INT32 rate_time;
    U_INT8 rate_index;
    U_INT32 delta;
    U_INT32 init_pres;
    U_INT32 final_pres;
    U_INT32 pres_rate;
    U_INT32 Po;

    RAMPTBL *setpts;
    RAMPS   *ramps;

    setpts = ((pRAMPINFO)GetRampInfoPtr( status ))->ramp_table;
    ramps  = ((pRAMPINFO)GetRampInfoPtr( status ))->ramps;

    Po = GetNtpOutletPressure( status );

    if ( ramps[0].rate == 0 )
    {
         rate_time = 0;
    }
    else
    {
         delta = ( ramps[0].final_value > setpts->init_value)?
                   ramps[0].final_value - setpts->init_value :
                   setpts->init_value - ramps[0].final_value ;

         /* msec   =                         mL/min* msec/min   / mL/min/min   */
         rate_time = QuadWordMultiplyDivide( delta, 60 * 1000  , ramps[0].rate );
    }

    cum_time = setpts->init_time;

    init_pres = CalcPiFromVFlow ( COL_F_UNITS(setpts->init_value),
                                  pOvenRamp()->ramp_table->init_value,
                                  Po,
                                  status );

    final_pres = CalcPiFromVFlow ( COL_F_UNITS(ramps[0].final_value),
                                   CalcTempFromTime( cum_time + rate_time ),
                                   Po,
                                   status );

    if ( rate_time == 0 )
    {
         pres_rate = 0;
    }
    else
    {
         /* psi/min */
         pres_rate = QuadWordMultiplyDivide ( (final_pres > init_pres) ?
                                               final_pres - init_pres  :
                                               init_pres  - final_pres, /* psi      */
                                              60 * 1000,                /* msec/min */
                                              rate_time );              /* msec     */
    }

    setpts->init_value = RAMP_P_UNITS(init_pres);

    init_pres = final_pres;
    cum_time = cum_time + rate_time + ramps[0].final_time;


    for ( rate_index = 1; rate_index < RAMP_LEVELS ; rate_index++ )
    {

        if ( ramps[rate_index].rate == 0 )
        {
             rate_time = 0;
        }
        else
        {
            delta = ( ramps[rate_index  ].final_value > ramps[rate_index-1].final_value)?
                      ramps[rate_index  ].final_value - ramps[rate_index-1].final_value :
                      ramps[rate_index-1].final_value - ramps[rate_index  ].final_value ;

            /* msec   =                         mL/min* msec/min   / mL/min/min   */
            rate_time = QuadWordMultiplyDivide( delta, 60 * 1000 , ramps[rate_index].rate );
        }

        ramps[rate_index-1].rate        = RAMP_P_UNITS(pres_rate);
        ramps[rate_index-1].final_value = RAMP_P_UNITS(final_pres);

        cum_time = cum_time + rate_time;

        final_pres = CalcPiFromVFlow ( COL_F_UNITS(ramps[rate_index].final_value),
                                       CalcTempFromTime( cum_time + rate_time ),
                                       Po,
                                       status );

        if ( rate_time == 0 )
        {
             pres_rate = 0;
        }
        else
        {
             /* psi/min */
             pres_rate = QuadWordMultiplyDivide ( (final_pres > init_pres) ?
                                                   final_pres - init_pres  :
                                                   init_pres  - final_pres, /* psi      */
                                                  60 * 1000,                /* msec/min */
                                                  rate_time );              /* msec     */
        }


        init_pres = final_pres;
        cum_time = cum_time + ramps[rate_index].final_time;

    }

    ramps[rate_index-1].rate        = RAMP_P_UNITS(pres_rate);
    ramps[rate_index-1].final_value = RAMP_P_UNITS(final_pres);

    /* now handle post time */

    setpts->post_value = RAMP_P_UNITS(CalcPiFromVFlow ( COL_F_UNITS(setpts->post_value),
                                                        pOvenRamp()->ramp_table->post_value,
                                                        Po,
                                                        status ));

    SetRampType( (pRAMPINFO)GetRampInfoPtr( status ), PRESSURE_RAMP );

}
/**begin_proto**/
#pragma SECTION UNDO
/**end_proto**/
